package dao

import (
	"Junior_two/subject/usercenter/userrpc/model"
	"fmt"
	"github.com/astaxie/beego/orm"
)

func RegInsert(u *model.Users) bool {
	o := orm.NewOrm()
	_, err := o.Insert(u)
	if err != nil {
		fmt.Println(err)
		return false
	}
	return true
}

func LogFliUsername(username string) bool {
	o := orm.NewOrm()
	u := model.Users{
		Username: username,
	}
	err := o.Read(&u, "username")
	if err != nil {
		fmt.Println(err)
		return false
	}
	return true
}

func LogFliPaw(username, password string) bool {
	o := orm.NewOrm()
	u := model.Users{
		Username: username,
	}
	err := o.Read(&u, "username")
	if err != nil {
		fmt.Println(err)
		return false
	}
	if u.Password != password {
		return false
	}
	return true
}

func UserInfo(username string) model.Users {
	o := orm.NewOrm()
	u := model.Users{
		Username: username,
	}
	err := o.Read(&u, "username")
	if err != nil {
		fmt.Println(err)
		return model.Users{}
	}
	return u
}
